/*
 * Copyright (C) Michael Opitz
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA
 */
#ifndef WORKER_THREAD_H
#define WORKER_THREAD_H

#include "thread_helper.h"

#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>

/** 
 * \brief This namespaces includes all nertwork related stuff.
 * \author Michael Opitz
 */
namespace network {
	/** 
	 * \brief This class implements a worker_thread
	 */
	class worker_thread : public network::thread_helper {
	public:
		worker_thread();
		virtual ~worker_thread();

		/** 
		 * \brief run runs the thread. This method should be implemented
		 * by sub-classes.
		 */
		virtual void run() = 0; 

		/** 
		 * \brief start_thread starts the worker_thread.
		 */
		void start_thread();
		/** 
		 * \brief join joins the worker_thread.
		 */
		void join() {_thread->join();}
	private:
		boost::function0<void> _fun;
		boost::shared_ptr<boost::thread> _thread;
	};
}

#endif
